<template>
  <div>
    <van-cell-group>
      <van-field v-model="AddDate.name" placeholder="请输入商品名称" />
    </van-cell-group>
    <div class="add">
      <van-button class="button" type="info" size="large" @click="AddList"
        >添加商品</van-button
      >
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      AddDate: {
        name: ''
      }
    }
  },
  methods: {
    // 添加按钮的点击事件
    async AddList(name) {
      if (this.AddDate.name.trim().length === 0) {
        return this.$notify({
          message: '请输入商品名称'
        })
      }
      var { data: res } = await this.$http.post(`/api/addproduct`, {
        name: this.AddDate.name
      })
      if (res.status !== 0) {
        return this.$notify({
          message: '添加失败'
        })
      }

      this.$notify({
        message: '添加成功',
        duration: 1500,
        background: 'green'
      })
      this.$router.push('/search')
    }
  }
}
</script>
<style lang="less" scoped>
.add {
  padding-left: 10px;
  padding-right: 10px;
}
.button {
  margin-top: 40px;
  height: 45px;
  line-height: 45px;
}
</style>
